package com.zzyl.service.impl;

import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    @Override
    public void addBed(BedDto bedDto) {
        //创建Bed床位对象
        Bed bed = new Bed();
        //把bedDto对象的数据拷贝到bed对象中
        BeanUtils.copyProperties(bedDto, bed);
        bed.setCreateTime(LocalDateTime.now());
        bed.setCreateBy(1L);
        bed.setBedStatus(0);

        //调用Mapper创建床位
        bedMapper.addBed(bed);
    }

    @Override
    public BedVo getBedsId(Long id) {
        //调用mapper查询根据ID查询床位
        BedVo bed = bedMapper.getBedById(id);
        return bed;
    }

    //删除床位
    @Override
    public void removeById(Long id) {
        bedMapper.removeById(id);
    }


    // 修改床位
    @Override
    public void updateBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto, bed);
        bedMapper.modifyBed(bed);
    }
}

